using UnityEngine;

/// <summary>
/// 设置最顶层显示
/// </summary>
public class User32Demo : MonoBehaviour
{



    const int SW_SHOWMINIMIZED = 2; //{最小化, 激活}  
    const int SW_SHOWMAXIMIZED = 3;//最大化  
    const int SW_SHOWRESTORE = 1;//还原  

    float waitsec = 30;
    float cursec = 0;
    private void Update()
    {
        if (cursec < waitsec)
        {
            cursec += Time.deltaTime;
        }
        else
        {
            cursec = 0;
#if !UNITY_EDITOR
            OnClickMaximize();
            User32API.SetForegroundWindow(User32API.GetCurrentWindowHandle());
#endif
        }
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }
    }

    private void Start()
    {
#if UNITY_EDITOR
#else
    OnClickMaximize();
#endif
        User32API.SetForegroundWindow(User32API.GetCurrentWindowHandle());
    }
    public void OnClickMinimize()
    {
        //最小化   
        User32API.ShowWindow(User32API.GetCurrentWindowHandle(), SW_SHOWMINIMIZED);
        Debug.Log("最小化");
    }


    public void OnClickMaximize()
    {
        //最大化  
        User32API.ShowWindow(User32API.GetCurrentWindowHandle(), SW_SHOWMAXIMIZED);
        //Debug.Log("最大化");
    }


    public void OnClickRestore()
    {
        //还原  
        User32API.ShowWindow(User32API.GetCurrentWindowHandle(), SW_SHOWRESTORE);
    }
}